﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Unity;
using PJ.Business.Partner;
using PJ.Business.Inventory;
using Microsoft.Practices.Composite.Events;

namespace PJ.Presentation.Inventory
{
    public class InventoryModule : IModule
    {
        private readonly IRegionManager m_RegionManager;
        private readonly IUnityContainer m_Container;

        public InventoryModule(IUnityContainer container, IRegionManager regionManager)
        {
            this.m_Container = container;
            this.m_RegionManager = regionManager;
        }

        public void Initialize()
        {
            RegisterViewsAndServices();
            IInventoryItemBasicInfoPresentationModel InventoryItemBasicInfo = m_Container.Resolve<IInventoryItemBasicInfoPresentationModel>();
            m_RegionManager.Regions["InfoRegion"].Add(InventoryItemBasicInfo.View);
            IGetInventoryItemPresenter getInventoryItem = m_Container.Resolve<IGetInventoryItemPresenter>();
            m_RegionManager.Regions["ToolsRegion"].Add(getInventoryItem.View);
        }

        private void RegisterViewsAndServices()
        {
//            IInventoryItemProvider ii = new PJ.Presentation.Inventory.InventoryItemProvider
                //(new PJ.Business.Inventory.InventoryItemService(), m_Container.Resolve<IEventAggregator>());
            m_Container.RegisterType<IInventoryItemSalesParamService, PJ.Business.Inventory.InventoryItemSalesParamService>();
            m_Container.RegisterType<IInventoryItemService, PJ.Business.Inventory.InventoryItemService>();
            m_Container.RegisterType<IInventoryItemProvider, PJ.Presentation.Inventory.InventoryItemProvider>(new ContainerControlledLifetimeManager());
            m_Container.RegisterType<IInventoryItemBasicInfoView, InventoryItemBasicInfoView>();
            m_Container.RegisterType<IInventoryItemBasicInfoPresentationModel, InventoryItemBasicInfoPresentationModel>();
            m_Container.RegisterType<IGetInventoryItemView, GetInventoryItemView>();
            m_Container.RegisterType<IGetInventoryItemPresenter, GetInventoryItemPresenter>();
        }
    }
}
